package com.ali.juejin.adapter

import android.content.Context
import com.ali.juejin.BR
import com.ali.juejin.R
import com.ali.juejin.base.BaseModelListAdapter
import com.ali.juejin.bean.CategoryItemBean
import com.ali.juejin.databinding.ItemCategoryBinding
import com.ali.juejin.model.CategoryModel
import com.blankj.utilcode.util.LogUtils
import kotlinx.android.synthetic.main.item_category.view.*

class HomeCategoryAdapter(mContext:Context,val model:CategoryModel): BaseModelListAdapter<ItemCategoryBinding, CategoryItemBean>(mContext,BR.categoryItem) {

    override fun getLayout(): Int {
        return R.layout.item_category
    }

    override fun onBindViewHolder(holder: ListHolder<ItemCategoryBinding>, position: Int) {
        super.onBindViewHolder(holder, position)
        holder.getBinding().setVariable(BR.categorySelectedItem,model.homeFollowCategorySelectedList.value!![position])
        holder.itemView.category_switch.setOnCheckedChangeListener { _, b ->
            val tempList = model.homeFollowCategorySelectedList.value!!
            tempList[position].isSubscribe = b
            model.homeFollowCategorySelectedList.postValue(tempList)
        }
    }

}